# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jaxlib/mlir:symlink_files.bzl", "symlink_files", "symlink_inputs")

package(
    default_visibility = [
        "//visibility:public",
    ],
)

# TODO: symlink_inputs currently doesn't support multiple entries in the nested
# dictionary of symlinked_inputs. Use symlink_files directly instead.
symlink_files(
    name = "dialect_core_py_files",
    srcs = ["@llvm-project//mlir/python:DialectCorePyFiles"],
    dst = "dialects",
)

py_library(
    name = "core",
    srcs = [
        ":dialect_core_py_files",
    ],
)

symlink_inputs(
    name = "ir",
    rule = py_library,
    symlinked_inputs = {"srcs": {
        ".": [
            "@llvm-project//mlir/python:IRPyFiles",
        ],
    }},
    deps = [
        ":mlir",
    ],
)

py_library(
    name = "mlir",
    deps = [
        "//jaxlib/mlir/_mlir_libs:_mlir",
    ],
)

symlink_inputs(
    name = "standard_dialect",
    rule = py_library,
    symlinked_inputs = {"srcs": {"dialects": [
        "@llvm-project//mlir/python:StandardOpsPyFiles",
    ]}},
    deps = [
        ":core",
        ":ir",
        ":mlir",
    ],
)

symlink_inputs(
    name = "builtin_dialect",
    rule = py_library,
    symlinked_inputs = {"srcs": {"dialects": [
        "@llvm-project//mlir/python:BuiltinOpsPyFiles",
    ]}},
    deps = [
        ":core",
        ":ir",
        ":mlir",
    ],
)

symlink_inputs(
    name = "mhlo_dialect",
    rule = py_library,
    symlinked_inputs = {"srcs": {"dialects": [
        "@org_tensorflow//tensorflow/compiler/mlir/hlo:MhloOpsPyFiles",
    ]}},
    deps = [
        ":core",
        ":ir",
        ":mlir",
        "//jaxlib/mlir/_mlir_libs:_mlirHlo",
    ],
)
